import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:ls_work/a_elder/models/elder_entity.dart';
import 'package:ls_work/message/message_config.dart';
import 'package:ls_work/net/post_request.dart';
import 'package:ls_work/net/response/activity_record_response.dart';
import 'package:ls_work/net/response/response_data.dart';
import 'package:ls_work/ui/activity/activity_record_page.dart';
import 'package:ls_work/ui/activity/activity_sign_page.dart';

class ActivityRecordViewModel
    extends BaseListViewModel<ActivityRecordListBean> {
  final ElderInfo? info;
  ActivityRecordViewModel(BuildContext context,{this.info}) : super(context){
    if(info!=null){
      customerNameLike = info?.name??"";
    }
  }

  var customerNameLike = "";
  var activityNameLike = "";

  @override
  Future<List<ActivityRecordListBean>> requestListData() async {
    var map = await PostRequest.activityRecord(
        customerNameLike, activityNameLike, startDateStr, endDateStr);
    // var bean = ActivityRecordResponse.fromJson(map);
    var bean = ResponseData<ActivityRecordListBean>.fromJson(map,listBuilder: (json){
      return ActivityRecordListBean.fromJson(json);
    });
    if ("0" == bean.code){
      return bean.data?.rows??[];
    }else{
      throw(bean.msg??"");
    }
  }

  @override
  void onCreated() {
    super.onCreated();
    requestRefresh();
  }

  void toAddSign(){
    Go().push(ActivitySignPage(info: info,));
  }

  @override
  void receiveMessage(SendMessageEvent event) {
    super.receiveMessage(event);
    if(event.msgCode==MessageConfig.FINISH_ACTIVITY_SIGN){
      requestRefresh(showAni: true);
    }
  }

}